// pages/creditScore/creditScore.js
const app = getApp();
const API = require('../../common/constant');
const util = require('../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    creditDTOList: [],
    creditcount: "",
    pageIndex: 1,
    pageCount: 0,
  },
  linkToPage(){
    wx.navigateTo({
      url: '../nameAuthentication/nameAuthentication'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  getCredit: function(){
    let that = this;
    wx.showLoading({
      title: '正则加载',
    })
    util.http({
      url: API.URL.USER.FIND_CREDITINFO,
      data: {
        pageIndex: this.data.pageIndex,
        pageSize: 4,
      },
      success: (res) => {
        console.log('我的信用积分是：', res);
        wx.hideLoading();
        if (res.data.bussData.creditDTOList){
          that.setData({
            isRealname: res.data.bussData.isRealname,
            creditcount: res.data.bussData.creditcount,
            creditDTOList: that.data.creditDTOList.concat(res.data.bussData.creditDTOList.bussData),
            pageCount: res.data.bussData.creditDTOList.pageCount,
            pageIndex: that.data.pageIndex + 1
          })
        }else{
          that.setData({
            isRealname: res.data.bussData.isRealname,
            creditcount: res.data.bussData.creditcount
          })
        }

      },
      fail: (res) => {
        console.log(res);
      }
    })
  },
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      pageIndex: 0,
      creditDTOList: []
    })
    this.getCredit();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.pageCount <= this.data.pageIndex) return
    this.setData({
      pageIndex: this.data.pageIndex + 1
    })
    this.getCredit();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})